package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.entity.SetmealDish;
import com.sky.enumeration.OperationType;
import lombok.Data;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Mapper
public interface SetmealDishMapper {

    /*
    根据菜品Id来
    查询对应的套餐ID*/
    //select setmeal_id from stemeal_dish where dish_id in (x,x,x,x) 需要使用动态SQL


    @AutoFill(value = OperationType.UPDATE)
    @Update("UPDATE setmeal " +
            "SET status = #{status} " +
            "WHERE id IN (SELECT setmeal_id " +
            "FROM setmeal_dish " +
            "WHERE dish_id = #{id})")
    void startOrStop(Long id, Integer status);


    /*套餐添加时  套餐菜品对应添加*/

    @AutoFill(value = OperationType.INSERT)
    void save(List<SetmealDish> setmealDish);

/*根据套餐id查询菜品*/
    @Select("select * from setmeal_dish where setmeal_dish.setmeal_id = #{id}")
    List<SetmealDish> getDishBySetmealId(Integer id);

/*根据菜品id获得套餐ID*/
    List<Integer> getSetmealIdsByDishIds(List<Integer> dishIds);


    /*删除对应套餐id的菜品*/

    @Delete("delete from setmeal_dish where setmeal_id = #{id}")
    void delete(Integer id);
}
